<template>
  <div>
   <i class="icon iconfont el-icon-screen-full screenFull" :icon-class="isFullscreen?'exit-fullscreen':'fullscreen'" @click="click"></i>
  </div>
</template>

<script setup>
import {ref, onBeforeUnmount} from 'vue'
import screenfull from 'screenfull'

let isFullscreen = ref(false)

function click () {
  console.log(screenfull.enabled)
  // if (!screenfull.enabled) {
  //   // this.$message({
  //   //   message: 'you browser can not work',
  //   //   type: 'warning'
  //   // })
  //   return false
  // }
  screenfull.toggle()
}

function change () {
  isFullscreen = screenfull.isFullscreen
}

function init (){
  if (screenfull.enabled) {
    screenfull.on('change', change)
  }
}
init()

function destroy () {
  if (screenfull.enabled) {
    screenfull.off('change', change)
  }
}

onBeforeUnmount(() => {
  destroy()
})
</script>

<style scoped>
.screenfull-svg {
  display: inline-block;
  cursor: pointer;
  fill: #5a5e66;;
  width: 20px;
  height: 20px;
  vertical-align: 10px;
}
</style>